from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome("C:\Program Files\driver\chromedriver.exe")
driver.maximize_window()

driver.get("https://www.baidu.com")
time.sleep(2)

# driver.find_element(By.XPATH, "//span[text()='搜索设置']")

# # 显示等待
# start_time = time.time()
# try:
#     element = WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//span[text()='搜索设置']")))
#     element.click()
# except:
#     pass
# end_time = time.time()
# print("等待耗时：", end_time-start_time)

# 隐式等待
driver.implicitly_wait(10)

start_time = time.time()
try:
    element = driver.find_element(By.XPATH, "//span[text()='搜索设置']")
    element.click()
except:
    pass
end_time = time.time()
print("等待耗时：", end_time-start_time)

time.sleep(2)
driver.quit()